import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        isLogin: !!localStorage.getItem('token'),
        isRouterAlive: true,
        userInfo: {}
    },
    mutations: {
        clearToken (state, params) {
            state.isLogin = false
            localStorage.removeItem('token')
        },
        setToken (state, params) {
            state.isLogin = true
            localStorage.setItem('token', params.token)
        },
        refreshRouter (state, params) { // 刷新当前页面
            state.isRouterAlive = false
            setTimeout(() => {
                state.isRouterAlive = true
            }, 200)
        }
    },
    actions: {},
    modules: {}
})
